package cn.njyd.corejava.thread.myday01;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

class TicketCallable implements Callable<Integer> {
    int num = 50;
    public Integer call() throws Exception{
        while(true) {
            if (num > 0) {
                System.out.println(Thread.currentThread().getName() + "卖出一张，还剩" + (--num) + "张");

            } else {
                System.out.println(Thread.currentThread().getName() + "票已卖完");
                break;
            }
        }
        return num;
    }

}


public class CallableDemo03 {
    public static void main(String[] args) {
        TicketCallable ticketCallable = new TicketCallable();
        for(int i=1;i<=4;i++) {
            new Thread(new FutureTask<>(ticketCallable),"窗口"+i).start();
        }
    }
}
